package huawei;
/*
* @Author: wanghongfucoder
* @Date:   2017-06-28 15:31:01
* @Last Modified by:   wanghongfucoder
* @Last Modified time: 2017-06-28 15:38:22
*/

import java.util.*;
  
public class Fama {
   
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()){
            int n = Integer.parseInt(sc.nextLine()); // n 种砝码
            String str1 = sc.nextLine();
            String str2 = sc.nextLine();
            System.out.println(getNums(n, str1, str2));
        }
        sc.close();
    }
   
    private static int getNums(int n, String str1, String str2) {
        String[] strings1 = str1.split(" ");
        String[] strings2 = str2.split(" ");
        int[] m = new int[n];
        int[] x = new int[n];
        int sum = 0; // 总的重量
        for (int i = 0; i < n; i++) {
            m[i] = Integer.valueOf(strings1[i]); // 每种砝码的重量
            x[i] = Integer.valueOf(strings2[i]); // 每种砝码的数量
            sum += x[i] * m[i];
        }
        boolean[] temp = new boolean[sum+1];
        temp[0] = true;
        temp[sum] = true;
        for (int i = 0; i < n; i++) {//砝码的种类数
            for (int j = 0; j < x[i]; j++) {//每种砝码对应的个数
                for (int k = sum; k >= m[i]; k--) {//总重量往下减
                    if (temp[k - m[i]])//递归思想的应用
                        temp[k] = true;
                }
            }
        }
        int count = 0;
        for (int i = 0; i <= sum; i++) {
            if (temp[i])
                count++;
        }//找到temp[]为true的，这是可以被称出来的；
        return count;
    }
}

/*


import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner cin=new Scanner(System.in);
        while(cin.hasNext()){
            int n=cin.nextInt();//砝码种类
            int[]  weights=new int[n];
            int[]  numbers=new int[n];
            for(int i=0;i<n;i++)
                weights[i]=cin.nextInt();
            for(int i=0;i<n;i++)
                numbers[i]=cin.nextInt();
            int result=function(n,weights,numbers);
            System.out.println(result);
        }
        cin.close();
    }
    public static int function(int n,int[] weights,int[] numbers){
        Set<Integer> set=new HashSet<Integer>();
        for(int i=0;i<=numbers[0];i++)
            set.add(i*weights[0]);
        for(int i=1;i<n;i++){//从第二个砝码开始
            List<Integer>list =new ArrayList<Integer>(set);
            for(int j=1;j<=numbers[i];j++){//遍历砝码的个数
                for(int k=0;k<list.size();k++)
                    set.add(list.get(k)+j*weights[i]);
            }
        }
        return set.size();
    }
}
 
 */